<%@page import="java.sql.Connection"%>
<%@page import="cn.jhc.dao.NewUserDao"%>
<%@page import="cn.jhc.bean.UserBean"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/houtai.css"></link>
<script type="text/javascript">
	function MM_popupMsg(msg) {
		alert(msg);
	}
</script>
<title>社团管理平台</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int titleCount = 10;
	%>
	<div id="wrapper">
		<jsp:include page="./houtai_header.jsp"></jsp:include>
		<div id="left">
			<div class="button2"><a href="houtai_showuser.jsp?search=no">用户信息</a></div>
			<div class="button"><a href="houtai_mailto.jsp">发送消息</a></div>
		</div>
		<div id="right">
			<div id="right_top">
			<%
				int UserNum;
				String search = request.getParameter("search");
				NewUserDao usernum = new NewUserDao();
				usernum.setCon(ConnectionFactory.getConnection());
				UserNum=usernum.getAllUser();
			%>
				<div id="addresstext"><a>所在位置： 用户信息<font color="red">(用户数：&nbsp;<%=UserNum%>)</font></a></div>
				<div id="sousuo">
				<form method="post" action="./houtai_search.do">
						<input type="text" name="name" id="name" size="21"
						value="请输入呢称" />
						<input type="submit" value="搜索用户"></input>
				</form>
				</div>
				<div id="num2">
					<form method="post" action="./houtai_openallvote.do">
					<input type="submit" value="开放所有投票" onclick="MM_popupMsg('开放投票！')"></input>
					</form>
				</div>
				<div id="xiaoxi" align="right">
					<form method="post" action="./houtai_mailto.jsp">
						<input type="submit" value="群发消息"></input>
					</form>
				</div>
			</div>
			<%
				request.setCharacterEncoding("UTF-8");
				ArrayList<UserBean> u = new ArrayList<UserBean>();
				NewUserDao dao = new NewUserDao();
				dao.setCon(ConnectionFactory.getConnection());
				u = dao.getAllUser(CurrentPage, titleCount);
				request.setAttribute("alluser", u);
			%>
			<%
				NewUserDao dao2 = new NewUserDao();
				dao2.setCon(ConnectionFactory.getConnection());
				intPageCount = dao2.getUserCount(titleCount);
				if(intPageCount==0){
					CurrentPage=1;
					intPageCount=1;
				}else{
					if (CurrentPage > intPageCount)
						CurrentPage = intPageCount;
				}
			%>
			<%if(search.equals("no")){%>
			<div id="right_news">
				<table width="100%">
					<tr>
						<th height="25">用户名</th>
						<th>呢称</th>
						<th>邮箱</th>
						<th>电话</th>
						<th>注册时间</th>
						<th>积分</th>
						<th>投票</th>
						<th colspan="3">操作</th>
					</tr>
					<%
						ArrayList list = (ArrayList) request.getAttribute("alluser");
							if (list != null) {
								for (int i = 0; i < list.size(); i++) {
									UserBean user = (UserBean) list.get(i);
					%>			
						<tr>
							<td height="25"><div align="center"><%=user.getName()%></div></td>
							<td><div align="center"><%=user.getDisplayname()%></div></td>
							<td><div align="center"><%=user.getEmail()%></div></td>
							<td><div align="center"><%=user.getPhone()%></div></td>
							<td><div align="center"><%=user.getDate()%></div></td>
							<td>
								<div align="center">
									<form method="post" action="./houtai_updateIntegral.do">
										<input type="text" name="integral" size="3" value="<%=user.getIntegral()%>"/>
										<input type="hidden" name="userid" value="<%=user.getId()%>">
									 	<input type="submit" value="更改"  onclick="MM_popupMsg('更改成功！')"></input>
									 </form>
								</div>
							</td>
							<%if(user.getVote().equals("no")){ %>
								<td><div align="center">未投票</div></td>
								<%}else{ %>
									<td><div align="center"><font color="red">已投票</font></div></td>
								<%} %>
							<td><div align="center"><a href="./deleteUser.do?id=<%=user.getId()%>" onclick="MM_popupMsg('删除成功！')">删除</a></div></td>
							<td><div align="center"><a href="./houtai_openVote.do?id=<%=user.getId()%>" onclick="MM_popupMsg('开放投票！')">开放投票</a></div></td>
							<td><div align="center"><a href="./houtai_mailto.jsp?id=<%=user.getId()%>">消息</a></div></td>
						</tr>
					<%
						}
							}
					%>
				</table>
				<div align="right">
					<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
					</a> <a href="houtai_showuser.jsp?page=<%=1%>&search=no">首页</a>
					<%
						if (CurrentPage > 1) {
					%>
					<a href="houtai_showuser.jsp?page=<%=CurrentPage - 1%>&search=no">上一页</a>
					<%
						} else {
					%>
					上一页
					<%
						}
					%>
					<%
						if (CurrentPage >= intPageCount) {
					%>
					下一页
					<%
						} else {
					%>
					<a href="houtai_showuser.jsp?page=<%=CurrentPage + 1%>&search=no">下一页</a>
					<%
						}
					%>
					<a href="houtai_showuser.jsp?page=<%=intPageCount%>&search=no">末页</a>
				</div>
			</div>
			<%}else if(search.equals("yes")){ %>
				<div id="right_news">
					<table width="100%">
					<tr>
						<th height="25">用户名</th>
						<th>呢称</th>
						<th>邮箱</th>
						<th>电话</th>
						<th>注册时间</th>
						<th>积分</th>
						<th>投票</th>
						<th colspan="3">操作</th>
					</tr>
						<%
						ArrayList list = (ArrayList) request.getAttribute("users");
							if (list != null) {
								for (int i = 0; i < list.size(); i++) {
									UserBean oneuser = (UserBean) list.get(i);
						%>			
						<tr>
							<td height="25"><div align="center"><%=oneuser.getName()%></div></td>
							<td><div align="center"><%=oneuser.getDisplayname()%></div></td>
							<td><div align="center"><%=oneuser.getEmail()%></div></td>
							<td><div align="center"><%=oneuser.getPhone()%></div></td>
							<td><div align="center"><%=oneuser.getDate()%></div></td>
							<td>
								<div align="center">
									<form method="post" action="./houtai_updateIntegral.do">
										<input type="text" name="integral" size="3" value="<%=oneuser.getIntegral()%>"/>
										<input type="hidden" name="userid" value="<%=oneuser.getId()%>">
									 	<input type="submit" value="更改"  onclick="MM_popupMsg('更改成功！')"></input>
									 </form>
								</div>
							</td>
							<%if(oneuser.getVote().equals("no")){ %>
								<td><div align="center">未投票</div></td>
								<%}else{ %>
									<td><div align="center">已投票</div></td>
								<%} %>
							<td><div align="center"><a href="./deleteUser.do?id=<%=oneuser.getId()%>" onclick="MM_popupMsg('删除成功！')">删除</a></div></td>
							<td><div align="center"><a href="./houtai_openVote.do?id=<%=oneuser.getId()%>" onclick="MM_popupMsg('开放投票！')">开放投票</a></div></td>
							<td><div align="center"><a href="./houtai_mailto.jsp?id=<%=oneuser.getId()%>">消息</a></div></td>
						</tr>
					<%
						}
							}
					%>
					</table>
				</div>
				<div align="center">
				<form method="post" action="./houtai_showuser.jsp?search=no">
					<input type="submit" value="返回"></input>
				</form>
				</div>
			<%}%>
		</div>
	</div>
</body>
</html>